#ifndef MYOPENGLWIDGET_H
#define MYOPENGLWIDGET_H

#include <QWidget>
#include <QOpenGLWidget>
#include <QOpenGLFunctions_3_3_Core>
#include <QOpenGLShaderProgram>
#include <QOpenGLTexture>
#include <QOpenGLBuffer>
#include <QOpenGLVertexArrayObject>


class MyOpenGLWidget : public QOpenGLWidget, public QOpenGLFunctions_3_3_Core
{
    Q_OBJECT

public:
    explicit MyOpenGLWidget();
    ~MyOpenGLWidget();

protected:
    void initializeGL()override;
    void resizeGL(int width, int height)override;
    void paintGL()override;

    //重写键盘事件
    void keyPressEvent(QKeyEvent *event)override;
    //重写鼠标事件
    void mouseMoveEvent(QMouseEvent *event)override;


private:
    QOpenGLShaderProgram *_shaderProgram;
    QOpenGLTexture *_texture;
    QOpenGLTexture *_texture1;
    QOpenGLVertexArrayObject *_vao;
    QOpenGLBuffer *_vbo;
    QOpenGLBuffer *_ebo;

    QList<QVector3D> _cubePositions = {
        QVector3D( 0.0f,  0.0f,  0.0f),
        QVector3D( 2.0f,  5.0f, -15.0f),
        QVector3D(-1.5f, -2.2f, -2.5f),
        QVector3D(-3.8f, -2.0f, -12.3f),
        QVector3D( 2.4f, -0.4f, -3.5f),
        QVector3D(-1.7f,  3.0f, -7.5f),
        QVector3D( 1.3f, -2.0f, -2.5f),
        QVector3D( 1.5f,  2.0f, -2.5f),
        QVector3D( 1.5f,  0.2f, -1.5f),
        QVector3D(-1.3f,  1.0f, -1.5f)
    };

    //帧处理时间
    int _lastMescCount = 0;
    float _deltaTime = 0;

    //摄像机相关
    QVector3D _cameraPos = {0.0f, 0.0f, 3.0f};
    QVector3D _cameraFront = {0.0f, 0.0f, -1.0f};
    QVector3D _cameraUp = {0.0f, 1.0f, 0.0f};
    float _moveSpeed = 5.0f;
    float _yaw = -90.0f;
    float _pitch = 0.0f;
    float _sensitivity = 0.1f;

    //屏幕中心点
    QPoint _lastMousePos = rect().center();


};

#endif // MYOPENGLWIDGET_H
